﻿`12@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>

    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src="~/Scripts/datagrid-detailview.js"></script>
    <title></title>
    <style type="text/css">
        .subtotal {
            font-weight: bold;
            color: black;
            /*//background-color: dodgerblue;*/
            height: 200px;
            width: 200px;
            font-size: 20px;
        }

        .subtotal2 {
            font-weight: bold;
            color: black;
            width: 6%;
            margin-top: 10px;
            background-color: orange;
            font-size: 20px;
        }
        /*合计单元格样式*/
    </style>
    <script type="text/javascript">
        $(function () {
            $("#shopName").combobox({
                url: pageConfig.getShopName,
                //action 
                valueField: "shopID",
                textField: "shopName"
            });
            //页面加载显示总金额    等同于下面  查询加载总金额  SaleMoney = SaleMoney, BuyMoney = BuyMoney, AllProfitMoney = SaleMoney - BuyMoney, Rate = (SaleMoney - BuyMoney)/SaleMoney 
            $.ajax({
                url: " /SaleDetail/GetRateAll?waresName=" + $("#txtName").val() + '&date1=' + $('#txtDate1').val() + '&date2=' + $('#txtDate2').val() + '&storeid=' + $("#shopName").combobox('getValue'),
                dataType: "JSON",
                type: "GET",
                success: function (data) {
                    //alert(data.SaleMoney);
                    $("#txtSaleMoney").val(data.SaleMoney + "元");
                    $("#txtBuyMoney").val(data.BuyMoney + "元");
                    $("#txtProfitMoney").val(data.AllProfitMoney + "元");
                    $("#txtRate").val(data.Rate);

                }
            });
        });

    </script>
    <script type="text/javascript">
        $(function () {
            //
            if ($("#shopName").combobox('getValue') == 0) {
                $("#shopName").combobox('setValue', "")
            }
            //
            $("#shopName").combobox({
                url: pageConfig.getShopName,
                valueField: "shopID",
                textField: "shopName"
            });
            //
            $("#data").datagrid({
                fit: true,
                title: '商品销售明细统计',
                halign: 'center',
                striped: true,
                rownumbers: true,
                collapsible: false, //是否可折叠  
                columns:
                    [[
                    {
                        field: 'waresCode',
                        title: '商品编码',
                        width: 150,
                        halign: 'center',

                        align: 'center'
                    }, {
                        field: 'waresName',
                        title: '商品名称',
                        width: 200,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'saleNum',
                        title: '已售数量',
                        width: 150,
                        halign: 'center',
                        align: 'center',
                        sortable: true

                    }, {
                        field: 'waresPrice',
                        title: '单个商品售价',
                        width: 150,
                        halign: 'center',
                        align: 'center',


                    }, {
                        field: 'waresBid',
                        title: '单个商品进价',
                        width: 150,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'saleMoney',
                        title: '商品出售总金额',
                        width: 160,
                        halign: 'center',
                        align: 'center',
                        sortable: true

                    }, {
                        field: 'buyMoney',
                        title: '商品进价总金额',
                        width: 150,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'ProfitMoney',
                        title: '商品盈利金额', //ProfitRateHidden
                        width: 150,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'ProfitRateHidden',
                        title: '盈利', //ProfitRateHidden
                        width: 150,
                        hidden:true,
                        halign: 'center',
                        align: 'center',

                    },
                    {
                        field: 'ProfitRate',
                        title: '销售利润率',
                        width: 150,
                        halign: 'center',
                        align: 'center',
                        sortable: true
                    },
                    ]],
                url: pageConfig.getAction,
                timeout: 3000,
                pagination: true,
                pageSize: 15,
                pageList: [15, 20, 25, 30, 35],
                sortName: 'saleMoney',//按盈利金额排序
                sortOrder: 'desc',
                toolbar: '#tool',
                //onLoadSuccess: function (data) {
                //    //要判断或者执行的代码  
                //    onLoadSuccess()
                //},
                //行的格式 单元格的格式   如果该商品已经下架 该行为灰色   如果该商品的货架实际数量<预警值
                rowStyler: function (index, row) {
                    if (row.validstatus = 0) {
                        return 'background-color:gray;color:#fff;font-weight:bold;';
                    }
                    if (row.waresActual <= row.waresWarning) {
                        return 'background-color:red;color:yellow;font-weight:bold;';
                    }
                },
                queryParams: {
                    waresName: $("#txtName").val(),
                    date1: $('#txtDate1').val(),
                    date2: $('#txtDate2').val(),
                    storeid: $("#shopName").combobox('getValue'),
                },
            });

            $('#data').datagrid({
                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:12px"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: '/SaleDetail/GetDetailEf',//一会记得修改过来
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        loadMsg: '',
                        height: 'auto',
                        columns: [[
                             //saleNum   startTime endTime    storeid  storeName
                             { field: 'storeid', title: '店铺编号', width: 100, color: 'red' },
                             { field: 'storeName', title: '店铺名称', width: 200, color: 'red' },
                             { field: 'saleNum', title: '销售数量', width: 100 },
                        ]],
                        onResize: function () {
                            $('#data').datagrid('fixDetailRowHeight', index);
                        },
                        queryParams: {
                            waresCode: row.waresCode,
                            date1: $('#txtDate1').val(),
                            date2: $('#txtDate2').val(),
                        }
                    });
                    $('#data').datagrid('fixDetailRowHeight', index);
                }
            });

        });

        var pageConfig = {

            getShopName: '@Url.Action("GetShopName")',
            getAction: '@Url.Action("GetAllBySql22")',
        };

        function searchData() {
            var start = $("#txtDate1").datebox('getValue');
            var end = $("#txtDate2").datebox('getValue');
            if (txtDate1.value > txtDate2.value) {
                alert("开始日期不能大于结束日期！");
                $("#txtDate1").datebox('setValue', "");//根据ID清空输入的时间
                $("#txtDate2").datebox('setValue', "");//根据ID清空
                txtDate1.focus();
                txtDate2.focus();
                return false;
            }
            $("#data").datagrid('load', {
                waresName: $("#txtName").val().trim(),//去除空格   
                date1: $('#txtDate1').val(),
                date2: $('#txtDate2').val(),
                storeid: $("#shopName").combobox('getValue'),

            });
            $.ajax({
                url: " /SaleDetail/GetRateAll?waresName=" + $("#txtName").val() + '&date1=' + $('#txtDate1').val() + '&date2=' + $('#txtDate2').val() + '&storeid=' + $("#shopName").combobox('getValue'),
                dataType: "JSON",
                type: "GET",
                success: function (data) {
                    //alert(data.SaleMoney);
                    $("#txtSaleMoney").val(data.SaleMoney + "元");
                    $("#txtBuyMoney").val(data.BuyMoney + "元");
                    $("#txtProfitMoney").val(data.AllProfitMoney + "元");
                    $("#txtRate").val(data.Rate);

                }
            });
        }

        function excelExport() {

            window.location.href = "/SaleDetail/ExportExcel?storeid=" + $("#shopName").combobox('getValue') + '&date1=' + $('#txtDate1').val() + '&date2=' + $('#txtDate2').val();
        }

    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>

    </div>


    <div id="tool" style="padding: 30px;">

        <div>
            商品名称：<input id="txtName" type="text" onchange="searchData()" />&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp    @* onchange 对回车事件时间有作用*@
            日期：<input id="txtDate1" type="text" class="easyui-datebox" onselect="searchData()" />
            --
            <input id="txtDate2" type="text" class="easyui-datebox" onselect="searchData()" />
            &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
             店铺名称：
                 <input id="shopName" class="easyui-combobox" name="shopName" />&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
            <a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">查询</a>
            &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
            <a class="easyui-linkbutton" iconcls="icon-print" onclick="excelExport();">导出Excel</a>
            <div style="margin-top: 20px;">
                <span style="font-size: larger; color: red">&nbsp&nbsp  &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp   注意：默认显示为今天销售的商品明细,可点击销售数量列 ＆出售总金额列进行排序</span>
                <br />
                &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp<span class="subtotal" style="">商品出售总金额：</span>
                <input id="txtSaleMoney" type="text" class="subtotal2" />
                &nbsp&nbsp&nbsp<span class="subtotal">进价总金额为：</span>
                <input id="txtBuyMoney" type="text" class="subtotal2" />
                &nbsp&nbsp&nbsp<span class="subtotal">盈利总金额：</span>
                <input id="txtProfitMoney" type="text" class="subtotal2" />
                &nbsp&nbsp&nbsp<span class="subtotal">销售利润率为：</span>
                <input id="txtRate" type="text" class="subtotal2" />
            </div>
        </div>
    </div>

</body>

</html>
<style>
    /* 设置数据行高 */
    .datagrid-row {
        height: 35px;
    }
</style>
